package resource.pojo;

import java.io.Serializable;
import java.sql.Date;
import java.sql.ResultSet;

import models.util.MySqlDataAccessHelper;

public class ListApprove implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Integer idListApprove;
	private String iDGroupApprove;
	private String iDEmployee;
	private Integer iDTypeApprove;
	private Integer order;
	private Integer iDStatus;
	private Date dateApprove;
	private String description;
	private Employee employee;
	private TypeApprove typeApprove;
	private GroupApprove groupApprove;
	private Status status;
	MySqlDataAccessHelper mysqlHelper = new MySqlDataAccessHelper();

	public MySqlDataAccessHelper getMysqlHelper() {
		return mysqlHelper;
	}

	public void setMysqlHelper(MySqlDataAccessHelper mysqlHelper) {
		this.mysqlHelper = mysqlHelper;
	}

	public ListApprove() {
	}

	public ListApprove(String id,String em) {
		this.iDGroupApprove = id;
		this.iDEmployee = em;
	}
	
	public ListApprove(Integer idListApprove, String iDGroupApprove,
			String iDEmployee, Integer iDTypeApprove, Integer order,
			Integer iDStatus, Date dateApprove, String description) {
		this.idListApprove = idListApprove;
		this.iDGroupApprove = iDGroupApprove;
		this.iDEmployee = iDEmployee;
		this.iDTypeApprove = iDTypeApprove;
		this.order = order;
		this.iDStatus = iDStatus;
		this.dateApprove = dateApprove;
		this.description = description;
	}

	public Integer getIdListApprove() {
		return idListApprove;
	}

	public void setIdListApprove(Integer idListApprove) {
		this.idListApprove = idListApprove;
	}

	public String getiDGroupApprove() {
		return iDGroupApprove;
	}

	public void setiDGroupApprove(String iDGroupApprove) {
		this.iDGroupApprove = iDGroupApprove;
	}

	public String getiDEmployee() {
		return iDEmployee;
	}

	public void setiDEmployee(String iDEmployee) {
		this.iDEmployee = iDEmployee;
	}

	public Integer getiDTypeApprove() {
		return iDTypeApprove;
	}

	public void setiDTypeApprove(Integer iDTypeApprove) {
		this.iDTypeApprove = iDTypeApprove;
	}

	public Integer getOrder() {
		return order;
	}

	public void setOrder(Integer order) {
		this.order = order;
	}

	public Integer getiDStatus() {
		return iDStatus;
	}

	public void setiDStatus(Integer iDStatus) {
		this.iDStatus = iDStatus;
	}

	public Date getDateApprove() {
		return dateApprove;
	}

	public void setDateApprove(Date dateApprove) {
		this.dateApprove = dateApprove;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public Employee getEmployee() {
		mysqlHelper.open();
		try {
			String sql = "select * from employee where IDEmployee = '"
					+ this.iDEmployee+"'";
			ResultSet rs = mysqlHelper.executeQuery(sql);
			while (rs.next()) {
				employee = new Employee(rs.getString("IDEmployee"),
						rs.getString("UserName"), rs.getString("Password"),
						rs.getString("FullName"), rs.getString("Phone"),
						rs.getDate("Birthday"), rs.getString("Address"),
						rs.getString("Email"), rs.getString("Sex"),
						rs.getString("Position"), rs.getString("IDManager"),
						rs.getInt("IDDepartment"), rs.getInt("IDRole"),
						rs.getString("Description"));
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			mysqlHelper.close();
		}
		return employee;
	}

	public void setEmployee(Employee employee) {
		this.employee = employee;
	}

	public TypeApprove getTypeApprove() {
		mysqlHelper.open();
		String sql = "select * from typeapprove where IDTypeApprove = "
				+ this.iDTypeApprove;
		try {

			ResultSet rs = mysqlHelper.executeQuery(sql);
			while (rs.next()) {
				Integer Id = rs.getInt("IDTypeApprove");
				typeApprove = new TypeApprove(Id);
				ConfigStaticLang confLang = typeApprove.getConfigStaticLang();
				if (confLang != null) {
					typeApprove.setIdTypeApprove(Id);
					typeApprove.setTypeName(confLang.getNameByLang("EN"));
					typeApprove.setDescription(rs.getString("Description"));
				} else {
					typeApprove = new TypeApprove(Id, rs.getString("TypeName"),
							0, rs.getString("Description"));
				}

			}
		} catch (Exception e) {
		} finally {
			mysqlHelper.close();
		}
		return typeApprove;
	}

	public void setTypeApprove(TypeApprove typeApprove) {
		this.typeApprove = typeApprove;
	}

	public Status getStatus() {
		mysqlHelper.open();
		try {
			String sql = "select * from status where IDStatus="
					+ this.getiDStatus();
			ResultSet rs = mysqlHelper.executeQuery(sql);
			if (rs.next()) {
				status = new Status(rs.getInt("IDConfigStaticLang"));
				ConfigStaticLang configStaticLang = status
						.getConfigStaticLang();
				if (configStaticLang != null) {
					status.setiDStatus(rs.getInt("IDStatus"));
					status.setStatusName(configStaticLang.getNameByLang("EN"));
					status.setDescription(rs.getString("Description"));
				} else {
					status.setiDStatus(rs.getInt("IDStatus"));
					status.setStatusName(rs.getString("StatusName"));
					status.setDescription(rs.getString("Description"));
				}
			}
		} catch (Exception e) {
		} finally {
			mysqlHelper.close();
		}
		return status;
	}

	public void setStatus(Status status) {
		this.status = status;
	}

	public GroupApprove getGroupApprove() {
		mysqlHelper.open();
		try {
			String sql = "select * from groupapprove where IDGroupApprove = '"
					+ this.iDGroupApprove+"'";
			ResultSet rs = mysqlHelper.executeQuery(sql);
			while (rs.next()) {
				groupApprove = new GroupApprove(rs.getString("IDGroupApprove"),
						rs.getBoolean("StatusUse"), rs.getString("GroupName"),
						rs.getString("Description"));
			}
		} catch (Exception e) {
		} finally {
			mysqlHelper.close();
		}
		return groupApprove;
	}

	public void setGroupApprove(GroupApprove groupApprove) {
		this.groupApprove = groupApprove;
	}
}
